<!DOCTYPE html>
<html lang="en">
<head>
  <title>Vert.x Docker Images - Vert.x</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="Vert.x is a tool-kit for building reactive applications on the JVM." name="description">
  <link href="http://vertx.io/stylesheets/docs.css" media="screen" rel="stylesheet">
  <link href="http://vertx.io/stylesheets/font-awesome.min.css" media="screen" rel="stylesheet">
  <link href="http://vertx.io/javascripts/styles/rainbow.min.css" media="screen" rel="stylesheet">
  <!-- IE 6-8 support of HTML 5 elements -->
  <!--[if lt IE 9]>
  <script src="http://static.jboss.org/theme/js/libs/html5/pre3.6/html5.min.js"></script>
  <![endif]-->

  <link rel="apple-touch-icon" sizes="57x57" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="60x60" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="72x72" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="76x76" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="114x114" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="120x120" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="144x144" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="152x152" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-152x152.png">
  <link rel="apple-touch-icon" sizes="180x180" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-180x180.png">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-32x32.png" sizes="32x32">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/android-chrome-192x192.png" sizes="192x192">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-16x16.png" sizes="16x16">
  <link rel="manifest" href="http://vertx.io/assets/favicons/vertx-favicon-7/manifest.json">
  <link rel="mask-icon" href="http://vertx.io/assets/favicons/vertx-favicon-7/safari-pinned-tab.svg" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#7d3194">
  <meta name="msapplication-TileImage" content="http://vertx.io/assets/favicons/vertx-favicon-7/mstile-144x144.png">
  <meta name="theme-color" content="#ffffff">

  <link href="http://fonts.googleapis.com/css?family=Ubuntu:400,500,700,400italic" rel="stylesheet" type="text/css">
  <link rel="alternate" type="application/rss+xml" title="RSS"
     href="http://vertx.io/feed.xml">
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-30144458-1', 'auto');
    ga('create', 'UA-71153120-1', 'auto', 'tracker');
    ga('send', 'pageview');
    ga('tracker.send', 'pageview');
  </script>
</head>
<body>

<a href="http://www.reactivemanifesto.org/" id="reactive-manifesto-banner">
  <img style="border: 0; position: fixed; right: 0; top:0; z-index: 9000"
    src="http://d379ifj7s9wntv.cloudfront.net/reactivemanifesto/images/ribbons/we-are-reactive-black-right.png">
</a>

<a id="skippy" class="sr-only sr-only-focusable" href="#content"><div class="container"><span class="skiplink-text">Skip to main content</span></div></a>

<header class="navbar navbar-default navbar-static-top" id="top" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#vertx-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="http://vertx.io/" class="navbar-brand"><img alt="Brand" src="http://vertx.io/assets/logo-sm.png"></a>
    </div>
    <nav class="collapse navbar-collapse" id="vertx-navbar-collapse">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="http://vertx.io/download/">Download</a></li>
        <li><a href="http://vertx.io/docs/">Documentation</a></li>
        <li><a href="https://github.com/vert-x3/wiki/wiki">Wiki</a></li>
        <li><a href="http://vertx.io/community/">Community</a></li>
        <li><a href="http://vertx.io/materials/">Materials</a></li>
        <li><a href="http://vertx.io/blog/">Blog</a></li>        
      </ul>
    </nav>
  </div>
</header>



  <div class="page-header" id="content">
    <div class="container">
      <div class="row">
        <div class="col-sm-12">
          <h1>Vert.x Docker Images</h1>
          
        </div>
      </div>
    </div>
  </div>




<div id="content">
  <div class="container docs-content">
    <div class="row">
      <div class="col-sm-12 col-md-push-9 col-md-3 hidden-xs hidden-sm">
        <div id="sidebar" data-spy="affix">
          <ul class="sectlevel1">
<li><a href="#_introduction">Introduction</a></li>
<li><a href="#_the_base_image">The base image</a>
<ul class="sectlevel2">
<li><a href="#_deploying_a_javascript_verticle_in_a_docker_container">Deploying a JavaScript verticle in a docker container</a></li>
<li><a href="#_deploying_a_groovy_verticle_in_a_docker_container">Deploying a Groovy verticle in a docker container</a></li>
<li><a href="#_deploying_a_ruby_verticle_in_a_docker_container">Deploying a Ruby verticle in a docker container</a></li>
<li><a href="#_deploying_a_java_verticle_in_a_docker_container">Deploying a Java verticle in a docker container</a></li>
<li><a href="#_configuration">Configuration</a></li>
<li><a href="#_build_docker_images_with_maven">Build Docker Images with Maven</a></li>
<li><a href="#_build_docker_images_for_fabric_8">Build Docker Images for Fabric 8</a></li>
</ul>
</li>
<li><a href="#_the_executable_image">The executable image</a></li>
<li><a href="#_deploying_a_fat_jar">Deploying a fat jar</a></li>
</ul>
        </div>
      </div>
      <div class="col-sm-12 col-md-pull-3 col-md-9">
        <div class="toc hidden-md hidden-lg">
          <h2>Table of Contents</h2>
          <ul class="sectlevel1">
<li><a href="#_introduction">Introduction</a></li>
<li><a href="#_the_base_image">The base image</a>
<ul class="sectlevel2">
<li><a href="#_deploying_a_javascript_verticle_in_a_docker_container">Deploying a JavaScript verticle in a docker container</a></li>
<li><a href="#_deploying_a_groovy_verticle_in_a_docker_container">Deploying a Groovy verticle in a docker container</a></li>
<li><a href="#_deploying_a_ruby_verticle_in_a_docker_container">Deploying a Ruby verticle in a docker container</a></li>
<li><a href="#_deploying_a_java_verticle_in_a_docker_container">Deploying a Java verticle in a docker container</a></li>
<li><a href="#_configuration">Configuration</a></li>
<li><a href="#_build_docker_images_with_maven">Build Docker Images with Maven</a></li>
<li><a href="#_build_docker_images_for_fabric_8">Build Docker Images for Fabric 8</a></li>
</ul>
</li>
<li><a href="#_the_executable_image">The executable image</a></li>
<li><a href="#_deploying_a_fat_jar">Deploying a fat jar</a></li>
</ul>
        </div>
        <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Execute Vert.x applications in Docker containers.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_introduction">Introduction</h2>
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://www.docker.com/">Docker</a> lets you deploy applications inside lightweight and isolated software containers.
Applications run side by side in isolated Linux containers. If you never used Docker before check this online <a href="https://www.docker.com/tryit/">tutorial</a>.</p>
</div>
<div class="paragraph">
<p>Vert.x provides Docker images that you can use to run your applications. Two Docker images are provided:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>vertx/vertx3</code> is the base image you need to extend to run your own application</p>
</li>
<li>
<p><code>vertx/vertx3-exec</code> is providing the <code>vertx</code> command to your system without having to install <code>vert.x</code> yourself.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The images are available from <a href="https://registry.hub.docker.com/repos/vertx/">Docker Hub</a>.</p>
</div>
<div class="paragraph">
<p>This guide presents how to use these two images but also how to automate Docker image creation using Maven, generate
Fabric8 metadata and use <em>fat jars</em>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_the_base_image">The base image</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The base image (<code>vertx/vertx3</code>) lets you run your vert.x application in a Docker container. For this, you must
<em>extend</em> the image to deploy your own application - <em>i.e.</em> create your own <code>Dockerfile</code> inheriting from
<code>vertx/vertx3</code>. Your application is then  launched using the <code>vertx</code> command (but in the container).</p>
</div>
<div class="sect2">
<h3 id="_deploying_a_javascript_verticle_in_a_docker_container">Deploying a JavaScript verticle in a docker container</h3>
<div class="paragraph">
<p>Let&#8217;s start with a simple JavaScript verticle such as:</p>
</div>
<div class="listingblock">
<div class="title">hello-verticle.js</div>
<div class="content">
<pre class="prettyprint highlight"><code class="language-javascript" data-lang="javascript">vertx.createHttpServer().requestHandler(function (request) {
    request.response().end("Hello world");
}).listen(8080);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Create in the same directory a <code>Dockerfile</code> with the following content:</p>
</div>
<div class="listingblock">
<div class="title">Dockerfile</div>
<div class="content">
<pre class="prettyprint highlight"><code># Extend vert.x image                       <b class="conum">(1)</b>
FROM vertx/vertx3

# Set the name of the verticle to deploy    <b class="conum">(2)</b>
ENV VERTICLE_NAME hello-verticle.js

# Set the location of the verticles         <b class="conum">(3)</b>
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

# Copy your verticle to the container       <b class="conum">(4)</b>
COPY $VERTICLE_NAME $VERTICLE_HOME/

# Launch the verticle                       <b class="conum">(5)</b>
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]</code></pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<p>First extend the image provided by vert.x</p>
</li>
<li>
<p>Set the name of the verticle</p>
</li>
<li>
<p>It sets the location in the container where the verticle file is placed</p>
</li>
<li>
<p>Copy the verticle files</p>
</li>
<li>
<p>Instructions to launch the verticle</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Then do build the image, just launch:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-shell" data-lang="shell">docker build -t sample/vertx-javascript .</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then, run it with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-shell" data-lang="shell">docker run -t -i -p 8080:8080 sample/vertx-javascript</code></pre>
</div>
</div>
<div class="paragraph">
<p>To see the result, open a browser to <a href="http://localhost:8080" class="bare">http://localhost:8080</a> or <a href="http://192.168.59.103:8080" class="bare">http://192.168.59.103:8080</a> if your are using boot2docker.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
The container is launched with the '-t -i` flags meaning <em>interactive</em>. Stop the container by hitting <code>CTRL+C</code>
. More details about the Docker <code>run</code> command are available <a href="http://docs.docker.com/reference/run/">here</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You may have noticed the <code>EXPOSE 8080</code> in the <code>Dockerfile</code> and the <code>-p 8080:8080</code> in the <code>run</code> command. The first one
is an optional information telling that the application wants to listen the port 8080. The second one is
<strong>mandatory</strong> and instructs docker to forward the port 8080 from the host to the 8080 of the container.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
You may also have noticed the convoluted way to launch the application. Instead of calling <code>vertx</code> directly, it
 uses <code>sh -c</code>. This is to turn around a Docker limitation not expanding variables in <code>CMD</code>. This way the launched
 shell does. More details on the Docker <a href="http://docs.docker.com/reference/builder/#cmd">builder documentation</a>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="_deploying_a_groovy_verticle_in_a_docker_container">Deploying a Groovy verticle in a docker container</h3>
<div class="paragraph">
<p>Running a groovy verticle in a docker container is not much different. Instead of the <code>hello-verticle.js</code> from the
previous example, we now have a <code>hello-verticle.groovy</code>:</p>
</div>
<div class="listingblock">
<div class="title">hello-verticle.groovy</div>
<div class="content">
<pre class="prettyprint highlight"><code class="language-groovy" data-lang="groovy">vertx.createHttpServer().requestHandler({ request -&gt;
    request.response().end("Groovy world")
}).listen(8080)</code></pre>
</div>
</div>
<div class="paragraph">
<p>So, in the <code>Dockerfile</code> we just change the verticle file name:</p>
</div>
<div class="listingblock">
<div class="title">Dockerfile</div>
<div class="content">
<pre class="prettyprint highlight"><code># Extend vert.x image
FROM vertx/vertx3

# Set the name of the verticle to deploy
ENV VERTICLE_NAME hello-verticle.groovy

# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

# Copy your verticle to the container
COPY $VERTICLE_NAME $VERTICLE_HOME/

# Launch the verticle
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The build and run instructions are very close to the previous ones:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>&gt; docker build -t sample/vertx-groovy .
....
&gt; docker run -t -i -p 8080:8080 sample/vertx-groovy</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_deploying_a_ruby_verticle_in_a_docker_container">Deploying a Ruby verticle in a docker container</h3>
<div class="paragraph">
<p>Running a groovy verticle in a docker container is not much different. Instead of the <code>hello-verticle.js/groovy</code> from
 the previous examples, we now have a <code>hello-verticle.rb</code>:</p>
</div>
<div class="listingblock">
<div class="title">hello-verticle.rb</div>
<div class="content">
<pre class="prettyprint highlight"><code class="language-ruby" data-lang="ruby">$vertx.create_http_server().request_handler() { |request|
    request.response().end("A ruby world full of gems")
}.listen(8080)</code></pre>
</div>
</div>
<div class="paragraph">
<p>So, in the <code>Dockerfile</code> we just change the verticle file name:</p>
</div>
<div class="listingblock">
<div class="title">Dockerfile</div>
<div class="content">
<pre class="prettyprint highlight"><code># Extend vert.x image
FROM vertx/vertx3

# Set the name of the verticle to deploy
ENV VERTICLE_NAME hello-verticle.rb

# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

# Copy your verticle to the container
COPY $VERTICLE_NAME $VERTICLE_HOME/

# Launch the verticle
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The build and run instructions are very close to the previous ones:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>&gt; docker build -t sample/vertx-ruby .
....
&gt; docker run -t -i -p 8080:8080 sample/vertx-ruby</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_deploying_a_java_verticle_in_a_docker_container">Deploying a Java verticle in a docker container</h3>
<div class="paragraph">
<p>So, now let&#8217;s see how to deploy a Java verticle. Again it&#8217;s not different from the previous examples, except that we
copy the verticle <em>jar</em> file to the container. Let&#8217;s take the following verticle:</p>
</div>
<div class="listingblock">
<div class="title">io.vertx.sample.hello.HelloVerticle</div>
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">package io.vertx.sample.hello;

import io.vertx.core.AbstractVerticle;

public class HelloVerticle extends AbstractVerticle {

  @Override
  public void start() throws Exception {
    vertx.createHttpServer().requestHandler(request -&gt; {
      request.response().end("Hello Java world");
    }).listen(8080);
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Let&#8217;s now imagine that this verticle is packaged into the <code>target/hello-verticle-1.0.-SNAPSHOT.jar</code> jar file. So the
<code>Dockerfile</code> needs to copy this file but also gives to vert.x the verticle class name:</p>
</div>
<div class="listingblock">
<div class="title">Dockerfile</div>
<div class="content">
<pre># Extend vert.x image
FROM vertx/vertx3

#                                                       <b class="conum">(1)</b>
ENV VERTICLE_NAME io.vertx.sample.hello.HelloVerticle
ENV VERTICLE_FILE target/hello-verticle-1.0-SNAPSHOT.jar

# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

# Copy your verticle to the container                   <b class="conum">(2)</b>
COPY $VERTICLE_FILE $VERTICLE_HOME/

# Launch the verticle
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]</pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<p>Unlike the previous examples, here we set the verticle class name and the jar file</p>
</li>
<li>
<p>The jar file is copied.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Build and run instructions do not change:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>&gt; docker build -t sample/vertx-java .
....
&gt; docker run -t -i -p 8080:8080 sample/vertx-java</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_configuration">Configuration</h3>
<div class="paragraph">
<p>The previous `Dockerfile`s did not configure vert.x. Let&#8217;s see how such configuration can be added.</p>
</div>
<div class="sect3">
<h4 id="_configuring_the_java_virtual_machine">Configuring the Java Virtual Machine</h4>
<div class="paragraph">
<p>You can configure the Java Virtual Machine using the <code>JAVA_OPTS</code> environment variable. So in the <code>Dockerfile</code> adds:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>ENV JAVA_OPTS "-Dfoo=bar"</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_vertx_opts">VERTX_OPTS</h4>
<div class="paragraph">
<p>System variables specific to vert.x can be configured using the <code>VERTX_OPTS</code> environment variable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>ENV VERTX_OPTS "-Dvertx.options.eventLoopPoolSize=26 -Dvertx.options.deployment.worker=true"</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_classpath">Classpath</h4>
<div class="paragraph">
<p>You can configure the classpath of the application using either the <code>-cp</code> parameter of the vert.x command or the
<code>CLASSPATH</code> environment variable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>ENV CLASSPATH "/usr/verticles/libs/foo.jar:/usr/verticles/libs/bar.jar:"</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_logging">Logging</h4>
<div class="paragraph">
<p>To configure the <code>logging.properties</code> file (that let you customize JUL loggers`), set the <code>VERTX_JUL_CONFIG</code>
environment variables:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>COPY ./logging.properties $VERTICLE_HOME/                       <b class="conum">(1)</b>
ENV VERTX_JUL_CONFIG $VERTICLE_HOME/logging.properties          <b class="conum">(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<p>Copy your <code>logging.properties</code> file</p>
</li>
<li>
<p>Set the <code>VERTX_JUL_CONFIG</code> environment variable</p>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="_clustering">Clustering</h4>
<div class="paragraph">
<p>You can provide your own <code>cluster.xml</code> file, and add it to the classpath. To build a dynamic classpath from all the
file contained in <code>$VERTICLE_HOME</code> you can use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>COPY ./cluster.xml $VERTICLE_HOME/
# ...
CMD [export CLASSPATH=`find $VERTICLE_HOME -printf '%p:' | sed 's/:$//'`; vertx run $VERTICLE_NAME"]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Notice the <code>export CLASSPATH=&#8230;&#8203;;</code> part in the <code>CMD</code> instruction. It builds the value of the <code>CLASSPATH</code> variable from
the content of the <code>$VERTICLE_HOME</code> directory. This tricks is useful to compute large and dynamic classpath.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_build_docker_images_with_maven">Build Docker Images with Maven</h3>
<div class="paragraph">
<p>There are a couple of Maven plugins to build your Docker images during your Maven build process. This example uses the
<a href="https://github.com/spotify/docker-maven-plugin">docker-maven-plugin</a> from Spotify.</p>
</div>
<div class="paragraph">
<p>First, create your Java project as usual. So your sources are located in <code>src/main/java</code>&#8230;&#8203; Then create a
<code>src/main/docker</code> directory and create a <code>Dockerfile</code> inside:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>.
├── pom.xml
├── src
│   └── main
│       ├── docker
│       │   └── Dockerfile
│       └── java
│           └── io
│               └── vertx
│                   └── example
│                       └── HelloWorldVerticle.java
├── target</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the <code>pom.xml</code> file add the following plugin configuration</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml">&lt;groupId&gt;com.spotify&lt;/groupId&gt;
&lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.2.8&lt;/version&gt;
&lt;executions&gt;
  &lt;execution&gt;
    &lt;id&gt;docker&lt;/id&gt;
    &lt;phase&gt;package&lt;/phase&gt;
    &lt;goals&gt;
      &lt;goal&gt;build&lt;/goal&gt;
    &lt;/goals&gt;
  &lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
  &lt;dockerDirectory&gt;${project.basedir}/src/main/docker&lt;/dockerDirectory&gt;
  &lt;!-- Configure the image name --&gt;
  &lt;imageName&gt;sample/vertx-hello&lt;/imageName&gt;
  &lt;resources&gt;
    &lt;resource&gt;
      &lt;targetPath&gt;/verticles&lt;/targetPath&gt;
      &lt;directory&gt;${project.build.directory}&lt;/directory&gt;
      &lt;includes&gt;
        &lt;include&gt;${project.artifactId}-${project.version}.jar&lt;/include&gt;
      &lt;/includes&gt;
    &lt;/resource&gt;
    &lt;!-- don't forget to also add all the dependencies required by your application --&gt;
  &lt;/resources&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The plugin copies the listed content into <code>target/docker</code>. Each resource is copied into the set <code>targetPath</code>. So edit
 the <code>src/main/docker/Dockerfile</code> and add the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>FROM vertx/vertx3

ENV VERTICLE_HOME /usr/verticles
ENV VERTICLE_NAME io.vertx.example.HelloWorldVerticle

COPY ./verticles $VERTICLE_HOME

ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]</code></pre>
</div>
</div>
<div class="paragraph">
<p>It&#8217;s basically the same content as we saw above. The copy is a bit different as the plugin have placed
files in the same directory as the <code>Dockerfile</code>.</p>
</div>
<div class="paragraph">
<p>Once configured the image is built using: <code>mvn clean package</code></p>
</div>
</div>
<div class="sect2">
<h3 id="_build_docker_images_for_fabric_8">Build Docker Images for Fabric 8</h3>
<div class="paragraph">
<p><a href="http://fabric8.io/">Fabric 8</a> is an open source set of micro-services that run on top of Kubernetes and OpenShift V3 to
 provide management, continuous delivery and iPaas facilities. You can execute vert.x application on top of Fabric 8
 by packaging them into a Docker image. However, additional metadata is required. In this example, we are going to
 use the <a href="https://github.com/rhuss/docker-maven-plugin">docker-maven-plugin</a> from Roland Huß.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s set up the following structure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>.
├── pom.xml
├── src
│   └── main
│       ├── docker
│       │   └── assembly.xml
│       └── java
│           └── io
│               └── vertx
│                   └── example
│                       └── HelloWorldVerticle.java
└── target</code></pre>
</div>
</div>
<div class="paragraph">
<p>Unlike the maven plugin from Spotify, this plugin takes an <code>assembly.xml</code> as input. The file lists all the files that
 need to be copied to the docker container such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml"> &lt;assembly&gt;
   &lt;dependencySets&gt;
     &lt;dependencySet&gt;
       &lt;includes&gt;
         &lt;include&gt;:${project.artifactId}&lt;/include&gt;
       &lt;/includes&gt;
       &lt;outputDirectory&gt;.&lt;/outputDirectory&gt;
     &lt;/dependencySet&gt;
   &lt;/dependencySets&gt;
 &lt;/assembly&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The rest of the <code>Dockerfile configuration is given in the `pom.xml</code> file. Add the following plugin to the <code>pom.xml</code>
 file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml"> &lt;plugin&gt;
  &lt;groupId&gt;org.jolokia&lt;/groupId&gt;
  &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
  &lt;version&gt;0.11.5&lt;/version&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;build&lt;/id&gt;
      &lt;phase&gt;package&lt;/phase&gt;
      &lt;goals&gt;
        &lt;goal&gt;build&lt;/goal&gt;
      &lt;/goals&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
  &lt;configuration&gt;
    &lt;images&gt;
      &lt;image&gt;
        &lt;name&gt;${docker.image}&lt;/name&gt;
        &lt;build&gt;
          &lt;from&gt;vertx/vertx3&lt;/from&gt;
          &lt;tags&gt;
            &lt;tag&gt;${project.version}&lt;/tag&gt;
          &lt;/tags&gt;
          &lt;ports&gt;
            &lt;port&gt;8080&lt;/port&gt;
          &lt;/ports&gt;
          &lt;command&gt;vertx run io.vertx.example.HelloWorldVerticle -cp
            /usr/verticles/${project.artifactId}-${project.version}.jar
          &lt;/command&gt;
          &lt;assembly&gt;
            &lt;mode&gt;dir&lt;/mode&gt;
            &lt;basedir&gt;/usr/verticles&lt;/basedir&gt;
            &lt;descriptor&gt;assembly.xml&lt;/descriptor&gt;
          &lt;/assembly&gt;
        &lt;/build&gt;
      &lt;/image&gt;
    &lt;/images&gt;
  &lt;/configuration&gt;
 &lt;/plugin&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>To configure the container more finely, check the
<a href="https://github.com/rhuss/docker-maven-plugin/blob/master/doc/manual.md">manual</a>. All the <em>instructions</em> we put in the
<code>Dockerfile</code> can be set from the plugin.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
The previous <code>pom.xml</code> file use a properties called <code>docker.image</code> setting the image name. Don&#8217;t forget to set
it in your pom.xml` file.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Once you have this configuration in place, we need a second plugin to generate the metadata required by Fabric8:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml">&lt;plugin&gt;
&lt;groupId&gt;io.fabric8&lt;/groupId&gt;
&lt;artifactId&gt;fabric8-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;2.1.4&lt;/version&gt;
&lt;executions&gt;
  &lt;execution&gt;
    &lt;id&gt;json&lt;/id&gt;
    &lt;phase&gt;generate-resources&lt;/phase&gt;
    &lt;goals&gt;
      &lt;goal&gt;json&lt;/goal&gt;
    &lt;/goals&gt;
  &lt;/execution&gt;
  &lt;execution&gt;
    &lt;id&gt;attach&lt;/id&gt;
    &lt;phase&gt;package&lt;/phase&gt;
    &lt;goals&gt;
      &lt;goal&gt;attach&lt;/goal&gt;
    &lt;/goals&gt;
  &lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once set up, you can build your docker image with: <code>mvn clean package</code>. It creates the <code>kubernates.json</code> file
required by Fabric8. Then push your image on the Docker Registry provided by Fabric8:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-sh" data-lang="sh">docker push $DOCKER_REGISTRY/sample/vertx-hello</code></pre>
</div>
</div>
<div class="paragraph">
<p>Don&#8217;t forget to set the <code>DOCKER_REGISTRY</code> url to point on the registry managed by Fabric8. The last step is to
<em>apply</em> it with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-sh" data-lang="sh">mvn io.fabric8:fabric8-maven-plugin:2.1.4:apply</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_the_executable_image">The executable image</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <code>vertx/vertx3-exec</code> image provides the <code>vertx</code> command to the host. So no need to install vert.x on your machine,
 you can just use this docker image.</p>
</div>
<div class="paragraph">
<p>For instance:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-shell" data-lang="shell">&gt; docker run -i -t vertx/vertx3-exec -version
3.0.0-SNAPSHOT</code></pre>
</div>
</div>
<div class="paragraph">
<p>To run a verticle:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-shell" data-lang="shell">docker run -i -t -p 8080:8080 \
    -v $PWD:/verticles vertx/vertx3-exec \
    run io.vertx.sample.RandomGeneratorVerticle \
    -cp /verticles/MY_VERTICLE.jar</code></pre>
</div>
</div>
<div class="paragraph">
<p>This command mounts the current directory (<code>PWD</code>) into <code>/verticles</code> and then launch the <code>vertx run</code> command. Notice the
<code>-cp</code> parameter reusing the <code>/verticles</code> directory.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_deploying_a_fat_jar">Deploying a fat jar</h2>
<div class="sectionbody">
<div class="paragraph">
<p>It is also possible to deploy a Vert.x application packaged as a <em>fat jar</em> into a docker container. For this you
don&#8217;t need the images provided by Vert.x, you can directly use a base <em>Java</em> image. Let&#8217;s have a look.</p>
</div>
<div class="paragraph">
<p>First, be sure your application is packaged as a <em>fat jar</em>. Then, use the following <code>Dockerfile</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>FROM java:8u77-jre-alpine                                           <b class="conum">(1)</b>

ENV VERTICLE_FILE hello-verticle-fatjar-3.0.0-SNAPSHOT-fat.jar      <b class="conum">(2)</b>

# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

# Copy your fat jar to the container
COPY target/$VERTICLE_FILE $VERTICLE_HOME/                          <b class="conum">(3)</b>

# Launch the verticle
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["java -jar $VERTICLE_FILE"]                                    <b class="conum">(4)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<p>Extend the image providing OpenJDK 8, use the one you want</p>
</li>
<li>
<p>Set the <code>VERTICLE_FILE</code> to point on the <em>fat jar</em></p>
</li>
<li>
<p>Copy the <em>Fat jar</em> from <em>target</em>. Change it if you don&#8217;t use Maven.</p>
</li>
<li>
<p>Launch the application using the <code>java</code> executable (instead of <code>vertx</code></p>
</li>
</ol>
</div>
<div class="paragraph">
<p>It&#8217;s basically the same <code>Dockerfile</code> as before. However, this time we extend <code>java:8</code> instead of the <code>vertx/vertx3</code>
image. Then we copy the fat jar to the container, and launch it with the <code>java</code> executable. All the configuration
settings presented above are still valid.</p>
</div>
<div class="paragraph">
<p>Build and run the container with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>&gt; docker build -t sample/vertx-java-fat .
....
&gt; docker run -t -i -p 8080:8080 sample/vertx-java-fat</code></pre>
</div>
</div>
</div>
</div>

        

        
          <div id="footer">
            <div id="footer-text">
              
                Last updated 2016-09-12 08:38:04 CEST
              
              
            </div>
          </div>
        
      </div>
    </div>
  </div>
</div>

<footer>
  <div class="container">
    <div class="row">
      <div class="col-xs-6 col-sm-3 col-md-3 col-lg-2">
        <h2>Vert.x</h2>
        <ul class="list-unstyled">
          <li><a href="http://vertx.io/">Home</a></li>
          <li><a href="http://vertx.io/download/">Download</a></li>
          <li><a href="http://vertx.io/docs/">Documentation</a></li>
          <li><a href="https://github.com/vert-x3/wiki/wiki">Wiki</a></li>
          <li><a href="http://vertx.io/blog/">Blog</a></li>
          <li><a href="http://vertx.io/vertx2/" class="vertx-2-link">Vert.x 2</a></li>
        </ul>
      </div>
      <div class="col-xs-6 col-sm-3 col-md-3 col-lg-2">
        <h2>Community</h2>
        <ul class="list-unstyled">
          <li><a href="http://vertx.io/community/">Help &amp; Contributors</a></li>
          <li><a href="http://vertx.io/materials/">Learning materials</a></li>
          <li><a href="https://groups.google.com/forum/?fromgroups#!forum/vertx">User Group</a></li>
          <li><a href="https://groups.google.com/forum/?fromgroups#!forum/vertx-dev">Developer Group</a></li>
        </ul>
      </div>

      <div class="col-xs-12 col-sm-6 col-lg-offset-2 col-md-6 copyright">
        <p>Vert.x is open source and dual licensed under the <a href="https://www.eclipse.org/org/documents/epl-v10.php">Eclipse Public License 1.0</a> and <a href="https://www.apache.org/licenses/LICENSE-2.0.html">Apache License 2.0</a>.</p>
        <p>This website is licensed under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0 License</a>.<br>
        Design by <a href="http://www.michel-kraemer.com">Michel Kr&auml;mer</a>. <a href="http://www.entypo.com">Entypo pictograms</a> by Daniel Bruce.</p>
        <div class="row">
          <div class="col-xs-12 col-lg-offset-1 col-md-5">
            <a href="http://eclipse.org">
            <img class="logo eclipse-logo" src="http://vertx.io/assets/eclipse_logo_grey_small.png" width="204" height="48">
            </a>
          </div>
          <div class="col-xs-12 col-md-offset-2 col-lg-offset-0 col-md-5">
            <a href="http://cloudbees.com">
            <img class="logo cloudbees-logo" src="http://vertx.io/assets/Button-Built-on-CB-1-grey.png" width="180" height="48">
           </a>
          </div>
          <div class="col-xs-12 col-md-offset-2 col-lg-offset-1 col-md-5 jprofiler">
            <a href="http://www.ej-technologies.com/products/jprofiler/overview.html"
            style="text-decoration:none">
            <img class="logo jprofiler-logo" src="http://vertx.io/assets/jprofiler-logo.png" width="48" height="48"><span class="jprofiler-logo">&nbsp; JPROFILER</span>
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</footer>

<script src="http://static.jboss.org/theme/js/libs/jquery/jquery-1.9.1.min.js"></script>
<script src="http://vertx.io/javascripts/bootstrap.min.js"></script>
<script src="http://vertx.io/javascripts/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



<script src="http://vertx.io/javascripts/sidebar.js"></script>


</body>
</html>
